import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { createHtmlPlugin } from 'vite-plugin-html'
import { viteMockServe } from 'vite-plugin-mock'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig({
  // base: '/',
  plugins: [
    vue({
      reactivityTransform: true
    }),
    // 默认自动加载 components 下的组件，通用级别组件
    Components({
      dts: false, // 默认开启自动生成类型声明文件，组件已经有类型声明文件，只要导入即可
      // 不需要自动导入样式，只需要自动导入组件
      resolvers: [VantResolver({ importStyle: false })]
    }),
    // svg打包
    createSvgIconsPlugin({
      // 将相对路径转成绝对路径
      iconDirs: [path.resolve(process.cwd(), 'src/icons')]
    }),
    createHtmlPlugin(),
    viteMockServe({
      // default
      mockPath: './src/mock',
      localEnabled: true
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 80,
    host: true,
    open: true
  }
})
